<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');

$sql_sel = "SELECT p.*, d.descr AS d_descr, m.id_set_dati, m.tipo_tab_indici "
		.", m.cod_mod_rbil, m.descr AS m_descr, s.descr AS s_descr " 
		." FROM rgl_mod_rbil m " 
		." LEFT JOIN rgl_mod_rbil_par_ind p ON p.id_mod_rbil = m.id_mod_rbil "
		."    AND p.cod_sett = '".reqVarAS('se')."'"
		." LEFT JOIN rgl_def_dato d ON d.cod_dato = p.cod_dato "
		."    AND d.id_set_dati = m.id_set_dati "
		." LEFT JOIN rgl_settore s ON s.cod_sett = p.cod_sett "
		." WHERE m.id_mod_rbil = ".reqVarInt('id')
		." ORDER BY p.cod_sett "
		;
$objDB->query($sql_sel,'selRec');
if (!$aRecPI = $objDB->fetch('selRec')) {
	die ('parIndSettMod - no id. '.$sql_sel);
}
$sql_sel = "SELECT d.cod_dato, d.descr FROM rgl_def_dato d " 
		." WHERE d.id_set_dati = ".$aRecPI['id_set_dati']
		." AND d.tipo_tab_dati = ".$aRecPI['tipo_tab_indici']
		." AND d.tipo_valore <> 'label' "
		." ORDER BY d.cod_dato "
		;
$objDB->query($sql_sel,'carDomZ');
$aCodDato = array(''=>'-- seleziona un indice');
while($acZ = $objDB->fetch('carDomZ')) {
	$aCodDato[$acZ['cod_dato']] = $acZ['cod_dato']." - ".substr($acZ['descr'],0,40);
}
$sql_sel = "SELECT d.cod_sett, d.descr FROM rgl_settore d " 
		." ORDER BY d.cod_sett "
		;
$objDB->query($sql_sel,'carDomZ');
$aCodSett = array(''=>'-- seleziona un settore','***'=>'*** - Settore generico');
while($acZ = $objDB->fetch('carDomZ')) {
	if (reqVar('se')=='' or reqVar('se')==$acZ['cod_sett'])
		$aCodSett[$acZ['cod_sett']] = $acZ['cod_sett']." - ".$acZ['descr'];
}
reqDef('cod_sett',reqVar('se'));
reqDef('cod_mod_rbil',$aRecPI['cod_mod_rbil']);
reqDef('m_descr',$aRecPI['m_descr']);
$nn=0;
if (!empty($aRecPI['cod_sett'])) while($aRecPI) {
	$nn++;
	reqDef('parind_cod_dato_'.$nn,$aRecPI['cod_dato']);
	reqDef('parind_soglia25_'.$nn,num2str($aRecPI['soglia25'],3));
	reqDef('parind_soglia50_'.$nn,num2str($aRecPI['soglia50'],3));
	reqDef('parind_soglia75_'.$nn,num2str($aRecPI['soglia75'],3));
	reqDef('parind_soglia100_'.$nn,num2str($aRecPI['soglia100'],3));
	reqDef('parind_media_rif_'.$nn,num2str($aRecPI['media_rif'],3));
	reqDef('parind_peso_'.$nn,num2str($aRecPI['peso'],0));
	$aRecPI = $objDB->fetch('selRec');
}
for($k=1;$k<4;$k++) {
	$nn += $k;
	reqDef('parind_cod_dato_'.$nn,'');
	reqDef('parind_soglia25_'.$nn,'');
	reqDef('parind_soglia50_'.$nn,'');
	reqDef('parind_soglia75_'.$nn,'');
	reqDef('parind_soglia100_'.$nn,'');
	reqDef('parind_media_rif_'.$nn,'');
	reqDef('parind_peso_'.$nn,10);
}
$cmdL = "";
$cmdR = "&nbsp;&nbsp;&nbsp;";
$cmdR .= "<a class=\"cmd1\" href=\"javascript:document.frm1.submit();\">salva</a>";
$cmdR .= cmdTorna(); 

testaHtml('Gestione modelli',  $msgPag, 'modl');
echo getHtmlForm();
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('id');
echo getHtmlHidden('se');
?>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="lab1" align="left" width='20%'>Modello</td>
      <td class="txt1" align="left" width='80%'>
         <?=getHtmlVisText('cod_mod_rbil')." - ".getHtmlVisText('m_descr')?>
      </td>
   </tr>
</table>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<?=getHtmlRigaRif();?>
   <tr>
      <td class="lab1" align='left' colspan='3'>Codice settore</td>
      <td class="txt1" align='left' colspan='17'>
<?
if (reqVar('se')=='') {
	echo getHtmlSelect('cod_sett',$aCodSett);
} else {
	echo getHtmlVisDecode('cod_sett',$aCodSett);
}
?>
		</td>
   </tr>
   <tr>
      <td class="lab1" align='center' colspan='9' rowspan='2'>Indice</td>
      <td class="lab1" align='center' colspan='8'>Soglie</td>
      <td class="lab1" align='center' colspan='2' rowspan='2'>Media</td>
      <td class="lab1" align='center' colspan='1' rowspan='2'>Peso</td>
   </tr>
   <tr>
      <td class="lab1" align='center' colspan='2'>25</td>
      <td class="lab1" align='center' colspan='2'>50</td>
      <td class="lab1" align='center' colspan='2'>75</td>
      <td class="lab1" align='center' colspan='2'>100</td>
   </tr>
         <? 
$clRF = 'txt2';
foreach($_REQUEST as $nX => $vX) {
	if (substr($nX,0,16)!='parind_cod_dato_') continue;
	$nn = substr($nX,16);
	$clRF = ($clRF=='txt1')?'txt2':'txt1';	
?>
   <tr>
      <td class="<?=$clRF?>" colspan='9'>
            <?
            echo getHtmlSelect('parind_cod_dato_'.$nn, $aCodDato);
            ?>
      </td>
      <td class="<?=$clRF?>" align='left' colspan='2'>
      	<? echo getHtmlTextNum('parind_soglia25_'.$nn, 5); ?>
      </td>
      <td class="<?=$clRF?>" align='left' colspan='2'>
      	<? echo getHtmlTextNum('parind_soglia50_'.$nn, 5); ?>
      </td>
      <td class="<?=$clRF?>" align='left' colspan='2'>
      	<? echo getHtmlTextNum('parind_soglia75_'.$nn, 5); ?>
      </td>
      <td class="<?=$clRF?>" align='left' colspan='2'>
      	<? echo getHtmlTextNum('parind_soglia100_'.$nn, 5); ?>
      </td>
      <td class="<?=$clRF?>" align='left' colspan='2'>
      	<? echo getHtmlTextNum('parind_media_rif_'.$nn, 5); ?>
      </td>
      <td class="<?=$clRF?>" align='left' colspan='1'>
      	<? echo getHtmlTextNum('parind_peso_'.$nn, 1); ?>
      </td>
   </tr>
<?    
}
?>
</table>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
</table>
<?
echo "</form>\n";
codaHtml();
exit();
